package com.banmao;

import cn.hutool.core.io.FileUtil;
import fr.opensagres.poi.xwpf.converter.pdf.PdfConverter;
import fr.opensagres.poi.xwpf.converter.pdf.PdfOptions;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;

@Slf4j
public class TestWord {

    public static void main(String[] args) throws Exception {

        //FileInputStream is = new FileInputStream();
        InputStream is = TestWord.class.getResourceAsStream("/test.docx");

        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        XWPFDocument xwpfDocument = new XWPFDocument(is);
        PdfOptions pdfOptions = PdfOptions.create();

        PdfConverter.getInstance().convert(xwpfDocument, bos, pdfOptions);
        URL resourceURL = TestWord.class.getResource("/");
        String path = resourceURL.getPath();
        log.info("path: {}", path);
        FileUtil.writeBytes(bos.toByteArray(), path + "test.pdf");
    }

}
